package main

import (
	"fmt"
	"github.com/gogf/gf/database/gredis"
	"github.com/gogf/gf/frame/g"
	"github.com/gogf/gf/util/gconv"
	"time"
)

var (
	config = gredis.Config{
		Host: "127.0.0.1",
		Port: 6379,
		Pass: "123456",
		Db:   0,
	}
)

func main1() {
	group := "test"
	gredis.SetConfig(config, group)

	redis := gredis.Instance(group)
	defer redis.Close()

	queueName := "test-queue"
	for {
		if length, _ := redis.Do("llen", queueName); gconv.Int(length) > 0 {
			r, err := redis.Do("lpop", queueName)
			if err != nil {
				panic(err)
			}
			g.Dump(r)
		} else {
			time.Sleep(time.Second * 1)
		}
	}
}

func main() {
	group := "test"
	gredis.SetConfig(config, group)
	conn := g.Redis(group).Conn()
	defer conn.Close()

	queueName := "test-queue"
	for {
		if length, _ := conn.Do("llen", queueName); gconv.Int(length) > 0 {
			res, err := conn.Do("lpop", queueName)
			if err != nil {
				panic(err)
			}
			fmt.Printf("%#v\n", gconv.String(res))
		} else {
			time.Sleep(time.Second * 1)
		}
	}
}
